<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>创建快件</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>
    <script type="text/javascript" src="js/cookie.js"></script>
</head>

<body>
<script>
    $(function () {
        $("#add").click(function (){
            var id=$("#L_id").val();
            var uId=$("#L_uId").val();
            $.ajax({
                url: "http://localhost:8080/es/get/"+uId,
                type: "get",
                dataType: "JSON",
                contentType : "application/json; charset=utf-8",
                success : function(data) {
                    var expressSheet=data.es;
                    if(expressSheet != null){
                        $.ajax({
                            url: "http://localhost:8080/es/create/"+id,
                            type: "post",
                            dataType: "JSON",
                            data:expressSheet,
                            contentType : "application/json; charset=utf-8",
                            success : function(data) {
                                //判断是否创建成功
                                if(data.code)
                                layer.msg('已创建!',{icon:1,time:1000});
                            },
                            error : function() {
                                alert("error");
                            }
                        });
                    }
                },
                error : function() {
                    alert("error");
                }
            });
        });
    });
</script>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="L_id" class="layui-form-label">
                <span class="x-red">*</span>快件单号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_id" name="id" required="" lay-verify="id" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_uId" class="layui-form-label">
                <span class="x-red">*</span>用户编号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_uId" name="uId" required="" lay-verify="uId" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button  class="layui-btn" id="add" lay-filter="add" lay-submit="">新建</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
        //自定义验证规则
        form.verify({
            id: function(value){
                if(value === '' || value === null){
                    return '姓名不能为空';
                }
            }
            ,uId: function(value) {
                if (value === '' || value === null) {
                    return '电话不能为空';
                }
            }
        });
        //监听提交
        form.on('submit(add)', function(data){
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("创建成功", {icon: 6},function () {
                //关闭当前frame
                x_admin_close();

                // 可以对父窗口进行刷新
                x_admin_father_reload();
            });
            return false;
        });
    });
</script>
</body>

</html>